*Hawes and McCrea "Hard Pill" JJP 2024 Replication File

use JPP_HardPill_Replication.dta

*Creating HC_Resources Index
*factor FQHC_pc Bup_Phys_pc Med_SA_pc SMAT_pc, pcf
*rotate
*predict HC_Resources
*lab var HC_Resources "Healthcare Resources Index"

*Models in Paper

*Table 1 - Drug-Related Deaths

sem (Penn_SC -> avgprescribrate, ) (Penn_SC -> HC_Resources, ) (Penn_SC -> avgcrudert   , ) (avgprescribrate -> HC_Resources, ) (avgprescribrate -> avgcrudert   , ) (HC_Resources -> avgcrudert   , ) (avgcrudert    -> HC_Resources, ) (mhh_time -> avgprescribrate, ) (mhh_time -> avgcrudert   , ) (unemploy_rt -> avgprescribrate, ) (unemploy_rt -> avgcrudert   , ) (mlf_partic -> avgprescribrate, ) (mlf_partic -> avgcrudert   , ) (mhh_income -> avgprescribrate, ) (mhh_income -> HC_Resources, ) (mhh_income -> avgcrudert   , ) (pct_debtcoll -> avgprescribrate, ) (pct_debtcoll -> avgcrudert   , ) (pov_rt -> avgprescribrate, ) (pov_rt -> avgcrudert   , ) (pct_graduatedcoll -> avgprescribrate, ) (pct_graduatedcoll -> HC_Resources, ) (pct_graduatedcoll -> avgcrudert   , ) (relig_cong -> avgprescribrate, ) (relig_cong -> avgcrudert   , ) (cnty_diversity -> avgprescribrate, ) (cnty_diversity -> avgcrudert   , ) (mj_law -> avgprescribrate, ) (mj_law -> avgcrudert   , ) (pct_need -> HC_Resources, ) (pct_need -> avgcrudert   , )  (den_rt -> avgcrudert   , ) (den_rt -> avgprescribrate  , ) (den_rt -> HC_Resources  , ) (pct_foreign_born -> avgcrudert   , ) (demleg -> HC_Resources, ) (demleg -> avgcrudert   , ), vce(cluster stateabrv) standardized nocapslatent
*nonlinear indirect effect (mediation)
nlcom (_b[avgcrudert:HC_Resources ]*_b[HC_Resources :Penn_SC])
*standardized
sum Penn_SC avgcrudert HC_Resources if e(sample)
nlcom (_b[avgcrudert:HC_Resources] * (_b[HC_Resources:Penn_SC] * (.7155598 /.8855721))) * (( .8855721 /  72.64594))
*standardized

*total effect
nlcom (total_effect: _b[avgcrudert:Penn_SC] + _b[avgcrudert:HC_Resources]*_b[HC_Resources:Penn_SC])
*Standardized
nlcom (total_effect: (_b[avgcrudert:Penn_SC] * (.7155598 / 72.64594)) + ((_b[avgcrudert:HC_Resources] * (.8855721 / 72.64594)) * (_b[HC_Resources:Penn_SC] * (.7155598 / .8855721))))

estat eqgof




*Table 2 - Deaths of Despair
sem (Penn_SC -> avgprescribrate, ) (Penn_SC -> HC_Resources, ) (Penn_SC -> mortality_rt_despair  , ) (avgprescribrate -> HC_Resources, ) (avgprescribrate -> mortality_rt_despair  , ) (HC_Resources -> mortality_rt_despair  , ) (mortality_rt_despair   -> HC_Resources, ) (mhh_time -> avgprescribrate, )  (unemploy_rt -> avgprescribrate, )  (mlf_partic -> avgprescribrate, ) (mlf_partic -> mortality_rt_despair  , ) (mhh_income -> avgprescribrate, ) (mhh_income -> HC_Resources, )  (pct_debtcoll -> avgprescribrate, )  (pov_rt -> avgprescribrate, )  (pct_graduatedcoll -> avgprescribrate, ) (pct_graduatedcoll -> HC_Resources, )  (relig_cong -> avgprescribrate, )  (cnty_diversity -> avgprescribrate, )  (mj_law -> avgprescribrate, ) (pct_need -> HC_Resources, ) (pct_need -> mortality_rt_despair  , )   (den_rt -> avgprescribrate  , ) (den_rt -> HC_Resources  , )  (demleg -> HC_Resources, ) , vce(cluster stateabrv) standardized nocapslatent
estat eqgof
*outreg2 using SEM_DoD, word se label replace stats(beta)
*nonlinear indirect effect (mediation)
sum Penn_SC mortality_rt_despair HC_Resources if e(sample)
*nonlinear indirect effect (mediation)
nlcom (_b[mortality_rt_despair:HC_Resources ]*_b[HC_Resources :Penn_SC])
*standardized
nlcom (_b[mortality_rt_despair:HC_Resources] * (_b[HC_Resources:Penn_SC] * (.6673922 /.6934381))) * ((.6934381 /  22.62871))
*total effect
nlcom (total_effect: _b[mortality_rt_despair:Penn_SC] + _b[mortality_rt_despair:HC_Resources]*_b[HC_Resources:Penn_SC])
*Standardized
nlcom (total_effect: (_b[mortality_rt_despair:Penn_SC] * (.6673922 / 22.62871)) + ((_b[mortality_rt_despair:HC_Resources] * (.6934381 / 22.62871)) * (_b[HC_Resources:Penn_SC] * (.6673922 / .6934381))))




****************************************************
**	IV-SEM 
**	Drug Deaths



*Durbin-Wu-Hausman (DWH) Test for Endogeneity:

*with controls
reg avgcrudert Penn_SC HC_Resources avgprescribrate pct_need  mlf_partic   pov_rt  den_rt   mhh_time    pct_foreign_born   demleg 
estimates store OLS_WCs

ivregress 2sls avgcrudert HC_Resources avgprescribrate pct_need  mlf_partic   pov_rt  den_rt   mhh_time    pct_foreign_born   demleg (Penn_SC =  pct_graduatedcoll   net_migration gdpqiFinance_an_e  mlf_segreg  talkneighbor favors    fixprob donate)

estimates store IV_WCs

hausman IV_WCs OLS_WCs

*chi2 = 37.58, p = 0.0000

hausman IV_WCs OLS_WCs, sigmamore
*chi2 = 61.74, p=0.0000


ivregress 2sls avgcrudert HC_Resources avgprescribrate pct_need  mlf_partic   pov_rt  den_rt   mhh_time    pct_foreign_born   demleg (Penn_SC =  pct_graduatedcoll   net_migration gdpqiFinance_an_e  mlf_segreg  talkneighbor favors    fixprob donate ), vce(robust) first
estat overid

*Sargan-Hansen test: Over-Identification Test for Endogeneity
*chi2 = 8.117, p=0.3223
*stage1 R2 = 0.3626 adjR2 = 0.3499
* F test in stage 1 = 30.64, greater than 10 = strong instruments




**************************************************

*IV-SEM Approach

*Appendix II - Table 1 
sem (Penn_SC <- talkneighbor favors    fixprob donate    gdpqiFinance_an_e  net_migration   mlf_segreg pct_foreign_born mlf_partic pov_rt den_rt mhh_time pct_graduatedcoll pct_need demleg)     (HC_Resources <- Penn_SC  pct_graduatedcoll mhh_income pct_need den_rt demleg  )  (HC_Resources <- avgcrudert) (HC_Resources <-avgprescribrate)   (avgprescribrate <- Penn_SC mhh_income mj_law relig_cong cnty_diversity pct_debtcoll mlf_partic pov_rt  den_rt   mhh_time)     (avgcrudert <- Penn_SC HC_Resources avgprescribrate pct_need  mlf_partic pov_rt  den_rt   mhh_time pct_foreign_born demleg pct_graduatedcoll mhh_income  unemploy_rt   pct_debtcoll   relig_cong cnty_diversity mj_law ),     vce(cluster stateabrv) standardized nocapslatent

estat eqgof
estat gof, stats(all)
*/
*nonlinear indirect effect (mediation)
nlcom (_b[avgcrudert:HC_Resources ]*_b[HC_Resources :Penn_SC])


*total effect
nlcom (total_effect: _b[avgcrudert:Penn_SC] + _b[avgcrudert:HC_Resources]*_b[HC_Resources:Penn_SC])



****************************************************
**	IV-SEM 
**	Deaths of Despair


*Durbin-Wu-Hausman (DWH) Test for Endogeneity:

*with controls
reg mortality_rt_despair Penn_SC HC_Resources avgprescribrate pct_need  mlf_partic   pov_rt  den_rt   mhh_time    pct_foreign_born   demleg 
estimates store OLS_WCs

ivregress 2sls mortality_rt_despair HC_Resources avgprescribrate pct_need  mlf_partic   pov_rt  den_rt   mhh_time    pct_foreign_born   demleg (Penn_SC =  pct_graduatedcoll   net_migration gdpqiFinance_an_e  mlf_segreg  talkneighbor favors    fixprob donate mlf_segreg net_migration mhh_income  unemploy_rt mj_law education_and_trai_c  relig_cong cnty_div pct_graduatedcoll  gdpqiFinance_an_e  pct_debtcoll  gdpqiManagement_e gdpqiManufactur_g)

estimates store IV_WCs

hausman IV_WCs OLS_WCs

*p = 0.0808

hausman IV_WCs OLS_WCs, sigmamore
*chi2 = 16.64, p=0.0000
*= difference in coefficients is systematic (i.e. endogeneity is a problem).



ivregress 2sls mortality_rt_despair HC_Resources avgprescribrate pct_need  mlf_partic   pov_rt  den_rt   mhh_time    pct_foreign_born   demleg (Penn_SC =  pct_graduatedcoll   net_migration gdpqiFinance_an_e  mlf_segreg  talkneighbor favors    fixprob donate mlf_segreg net_migration mhh_income  unemploy_rt mj_law education_and_trai_c  relig_cong cnty_div pct_graduatedcoll  gdpqiFinance_an_e  pct_debtcoll  gdpqiManagement_e gdpqiManufactur_g), vce(robust) first

estat overid 
*Sargan-Hansen test: Over-Identification Test for Endogeneity
*chi2 = 15.411, p=0.4948
*stage1 R2 = 0.4262
* F test in stage 1 = 27.58, greater than 10 = strong instruments



*Appendix II - Table 2 
sem (Penn_SC <- talkneighbor favors    fixprob donate relig_cong education_and_trai_c  gdpqiFinance_an_e  gdpqiManagement_e gdpqiManufactur_g cnty_div net_migration   mlf_segreg pct_foreign_born mlf_partic mhh_income pov_rt unemploy_rt den_rt mhh_time pct_debtcoll pct_graduatedcoll pct_need mj_law demleg)  (HC_Resources <- Penn_SC  pct_graduatedcoll mhh_income pct_need den_rt  demleg)  (HC_Resources <- mortality_rt_despair) (HC_Resources <-avgprescribrate)   (avgprescribrate <- Penn_SC cnty_diversity mlf_partic mhh_income   pov_rt  den_rt   mhh_time relig_cong pct_debtcoll  mj_law) (mortality_rt_despair <- Penn_SC HC_Resources avgprescribrate pct_need  mlf_partic   pov_rt  den_rt   mhh_time    pct_foreign_born   demleg ),     vce(cluster stateabrv) standardized nocapslatent

estat eqgof
estat gof, stats(all)
estat mindices

*nonlinear indirect effect (mediation)
nlcom (_b[mortality_rt_despair:HC_Resources ]*_b[HC_Resources :Penn_SC])


*total effect
nlcom (total_effect: _b[mortality_rt_despair:Penn_SC] + _b[mortality_rt_despair:HC_Resources]*_b[HC_Resources:Penn_SC])





